<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="事件来源" prop="updateFrom">
        <el-input
          v-model="queryParams.updateFrom"
          placeholder="请输入事件来源"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新标识" prop="updateSign">
        <el-input
          v-model="queryParams.updateSign"
          placeholder="请输入更新标识"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:update:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['system:update:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="updateList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="更新ID" align="center" prop="updateId" />
      <el-table-column label="事件类型" align="center" prop="updateType" />
      <el-table-column label="事件来源" align="center" prop="updateFrom" />
      <el-table-column label="更新标识" align="center" prop="updateSign" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script setup name="CmsUpdate">
import { listUpdate,  delUpdate} from "@/api/cms/update";

const { proxy } = getCurrentInstance();

const updateList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    updateType: null,
    updateFrom: null,
    updateSign: null,
  }
});

const { queryParams} = toRefs(data);

/** 查询内容更新列表 */
function getList() {
  loading.value = true;
  listUpdate(queryParams.value).then(response => {
    updateList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}


/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.updateId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _updateIds = row.updateId || ids.value;
  proxy.$modal.confirm('是否确认删除内容更新编号为"' + _updateIds + '"的数据项？').then(function() {
    return delUpdate(_updateIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('cms/update/export', {
    ...queryParams.value
  }, `update_${new Date().getTime()}.xlsx`)
}

getList();
</script>
